using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Singleton<T> : MonoBehaviour where T : Singleton<T>
{
    private static T instance;

    public static T GetInstance()
    {
        return instance;
    }

    protected virtual void Awake()
    {
        if(instance != null && gameObject != null)
        {
            Destroy(gameObject);
        } else
        {
            instance = (T)this;
        }

    }

    //public static T GetInstance()
    //{
    //    if(instance == null)
    //    {
    //        GameObject obj = new GameObject();
    //        obj.name = typeof(T).ToString();

    //        DontDestroyOnLoad(obj);
    //        instance = obj.AddComponent<T>();
    //    }
    //    return instance;
    //}

}
